package dao;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBUtil {
	private static Connection con;
	private static String driver;
	private static String url;
	private static String user;
	private static String password;
	private static String message;
	
	static{
		Properties p=new Properties();
		InputStream in=DBUtil.class.getResourceAsStream("../dao/db.properties");
		try {
			p.load(in);
			driver=p.getProperty("driver");
			url=p.getProperty("url");
			user=p.getProperty("user");
			password=p.getProperty("password");
			Class.forName(driver);
			con=DriverManager.getConnection(url,user,password);
			message="连接成功！";
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static Connection getCon() {
		return con;
	}
	
	public static String getMessage(){
		return message;
	}
}
